package com.fuhao.springboot.controller;

import com.fuhao.springboot.mapper.StudentsMapper;
import com.fuhao.springboot.model.Students;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 集成redis
 */
@RestController
public class RedisController {

    @Autowired
    private RedisTemplate<Object,Object> template;

    @Autowired
    private StudentsMapper studentsMapper;

    @RequestMapping(value = "/setCache/{id}")
    public void findById(@PathVariable Integer id){
        template.boundHashOps("All").put("students", studentsMapper.selectByPrimaryKey(id));
    }

    @RequestMapping(value = "/getCache/{id}")
    public Students getById(@PathVariable Integer id){
       return (Students) template.boundHashOps("All").get("students");
    }
}
